from time import sleep
from selenium import webdriver
from  selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import os.path


# 打开谷歌网站
driver = webdriver.Chrome()

# 打开注册网站
url ='file:///' + os.path.abspath('html') + '/注册实例.html'
driver.get(url)

# 用id定位账号
sleep(2)
driver.find_element(By.ID,'user').send_keys('666666')

# 用id定位密码
sleep(2)
driver.find_element(By.ID,'password').send_keys('666666')

# 用id定位手机号
sleep(2)
driver.find_element(By.ID,'tel').send_keys('12345678910')

# 用 id 定位邮箱
sleep(2)
driver.find_element(By.ID,'email').send_keys('1585685709@qq.com')

#用slect 定义城市
sleep(2)
slect = driver.find_element(By.ID,'select')
select = Select(slect)

# 选择 option
sleep(2)
select.select_by_value('sh')

# 定位alert
sleep(2)
alert = driver.find_element(By.ID,'alert')
alert.click()

# 获取弹窗
sleep(2)
alter = driver.switch_to.alert
alter.accept()  #确定


# 用 xpath 定位注册
sleep(2)
driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button').click()

# 退出浏览器
sleep(5)
driver.quit()



